package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.DaoSchoolArticleChildPageAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolArticleChildSaveAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolArticleChildUpdateSortAdminDTO;
import com.sc.nft.entity.vo.DaoSchoolArticleChildPageAdminVO;
import com.sc.nft.service.DaoSchoolArticleChildService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 文章表与子分类关联表(DaoSchoolArticleChild)表控制层
 *
 * @author makejava
 * @since 2023-03-13 16:21:22
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/daoSchoolArticleChild")
@Api(tags = "文章表与子分类关联")
public class DaoSchoolArticleChildController {

    /**
     * 服务对象
     */
    private final DaoSchoolArticleChildService daoSchoolArticleChildService;

    @ApiOperation(value = "列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/pageAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolArticleChildPageAdminVO> pageAdmin(@RequestBody DaoSchoolArticleChildPageAdminDTO pageRequest) {
        Page<DaoSchoolArticleChildPageAdminVO> daoSchoolArticleChildPageAdminVOPage = daoSchoolArticleChildService.pageAdmin(pageRequest);
        return PageResult.success(daoSchoolArticleChildPageAdminVOPage);
    }

    @ApiOperation(value = "文章关联删除", notes = "文章关联删除", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteById(@RequestBody @Validated IdRequest idRequest) {
        daoSchoolArticleChildService.deleteById(idRequest.getId());
        return Result.success();
    }

    @ApiOperation(value = "文章关联新增", notes = "文章关联新增", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result saveAdmin(@RequestBody @Validated List<DaoSchoolArticleChildSaveAdminDTO> info) {
        daoSchoolArticleChildService.saveAdmin(info);
        return Result.success();
    }

    @ApiOperation(value = "修改排序", notes = "修改排序", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateSortById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSortById(@RequestBody @Validated DaoSchoolArticleChildUpdateSortAdminDTO info) {
        daoSchoolArticleChildService.updateSortById(info);
        return Result.success();
    }

}
